/**
 * 
 */
package org.esprit.ocm.server.metier.ec2.impl;

import java.util.logging.Logger;

import org.esprit.ocm.dto.impl.AwsCredentialsDto;
import org.esprit.ocm.dto.impl.ServerDto;
import org.esprit.ocm.server.metier.ec2.BaseService;

import com.xerox.amazonws.ec2.Jec2;

/**
 * Base class for all functions that the service layer provides.
 * 
 * @author fbitzer
 * 
 */
public abstract class BaseServiceImpl implements BaseService {

	// /**
	// * Instance of the Typica interface.
	// */
	// protected Jec2 ec2;
	//
	// /**
	// * User's AWS credentials
	// */
	// protected AwsCredentialsDto credentials;
	//
	// /**
	// * User's server information
	// */
	// protected ServerDto server;

	/**
	 * Initialize connection to the cloud server with ec2
	 * 
	 * @return Jec2 object to use in Cloud Services
	 */
	public Jec2 initConnection(ServerDto server, AwsCredentialsDto credentials) {

		try {
			boolean isSecure = server.isUseHTTPS();

			Jec2 ec2 = new Jec2(credentials.getAwsAccessKeyId(), credentials.getSecretAccessKey(), isSecure, server.getIpServer(), server.getPort());
			ec2.setResourcePrefix(server.getResourcePrefix());
			ec2.setSignatureVersion(server.getSignatureVersion());

			return ec2;

		} catch (Exception ex) {

			Logger.getAnonymousLogger().severe("Initializing configuration failed.");
			ex.printStackTrace();
			return null;
		}
	}
}
